package interpreter;
import java.math.BigDecimal;


public class AssignExpr extends Expr{
	
	private Id id;
	private Expr value;
	
	private AssignExpr(Id id, Expr value){
		this.id = id;
		this.value = value;
	}
	
	public static Expr _(Id id, Expr value){
		return new AssignExpr(id, value);
	}

	@Override
	public BigDecimal evaluate(Env env) throws Exception{
		try{
			value.evaluate(env);
		} catch(Exception e){
			throw new Exception("Variable "+id.getV()+" not found");
		}
		env.put(id.getV(),value);
		return id.evaluate(env);
	}

}
